package com.oto.web.resource;

import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;

import com.sun.jersey.api.view.Viewable;

/**
 * @author xueqiang.mi
 * @since 2011-1-16
 */
@Provider
public class CustomExceptionMapper implements ExceptionMapper<WebApplicationException> {

	public Response toResponse(WebApplicationException ex) {
		int status = ex.getResponse().getStatus();
		switch (ex.getResponse().getStatus()) {
		case 404:
			return Response.status(status).entity(new Viewable("/error", "您请求的页面不存在。")).build();
		case 500:
			return Response.status(status).entity(new Viewable("/error", "服务器内部错误，请稍后再试。")).build();
		default:
			break;
		}
		return Response.status(status).entity(new Viewable("/error", "服务器内部错误，请稍后再试。")).build();
	}
}
